﻿using DotNetty.Buffers;
using DotNetty.Codecs;
using DotNetty.Transport.Channels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace socketAssist.Procol
{
    public class MyProcolEncoder: MessageToByteEncoder<RequestMessage>
    {
        protected override void Encode(IChannelHandlerContext context, RequestMessage message, IByteBuffer output)
        {
            var body = Encoding.UTF8.GetBytes(message.body);
            output.WriteIntLE(body.Length+1);
            output.WriteShortLE(message.Cmd);
            output.WriteByte(0);

            output.WriteBytes(body);
            output.WriteByte(0);
        }
    }
}
